{extend name="common/base" /}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            {include file="group/form" /}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="my_js"}
<script>
    layui.use(['element', 'admin', 'form', 'authtree'], function () {
        var element = layui.element
            , admin = layui.admin
            , authtree = layui.authtree
            , form = layui.form;
        var id = {$id};
        admin.ajax('admin/group/' + id, '', function (data) {
            form.val("", {
                "title": data.data.title
                ,"description": data.data.description
                ,"status": data.data.status
            })
        }, '', 'get');
        admin.ajax('admin/group/getAuth/' + id, '', function (data) {
            authtree.render('#LAY-auth-tree-index', data.data, {
                inputname: 'rules[]',
                layfilter: 'lay-check-auth',
                openall: false
            });
            form.on('checkbox(lay-check-auth)', function (data) {
                setTimeout(function () {
                    var leaf = authtree.getLeaf('#LAY-auth-tree-index');
                    console.log(leaf);
                }, 200);
            });
        }, '', 'get');
        form.on('submit(formGroup)', function (data) {
            data.field.status = data.field.status ? data.field.status : 0;
            admin.ajax('admin/group/' + id, data.field, function (data) {
                if (data.code == 1001) {
                    $('#layui-icon-refresh',parent.document).click();
                    layer.confirm(data.msg + ',是否返回?', {
                        icon: 3,
                        title: '提示',
                        btn: ['留下', '返回']
                    }, function (index) {
                        location.reload();
                    }, function () {
                        admin.closeSelf()
                    });
                } else {
                    layer.msg(data.msg);
                }
            }, '', 'PUT');
        });
    });
</script>
{/block}